Skip to content

[5.x] Add blueprint repository hook#11901

Closed
simonerd wants to merge 2 commits into
statamic:5.xfrom
simonerd:add-blueprint-hook
Closed

[5.x] Add blueprint repository hook#11901
simonerd wants to merge 2 commits into
statamic:5.xfrom
simonerd:add-blueprint-hook

Conversation

@simonerd

@simonerd simonerd commented Jun 26, 2025

Copy link
Copy Markdown
Contributor

We are exploring ways to reuse one blueprint in multiple collections to allow us to split up (otherwise identical) content into more collections for better performance, permission-control and usability. We want to avoid copy-pasting the blueprint file.

This PR introduces a hook to the makeBlueprintFromFile function in the BlueprintRepository. This would allow to change the path of the blueprint file and therefore use a different blueprint for an entry than its actually intended one.

Example

Say I have a collection pages with a blueprint page. I now need another collection subpages where the blueprint page should actually be identical with the one from pages. I can now add a hook like this:

Blueprint::hook('makeFromFile', function ($payload, $next) {
    if ($payload->namespace === "collections/subpages") {
        $payload->namespace = "collections/pages";
        $payload->path = str_replace("subpages/page.yaml", "pages/page.yaml", $payload->path);
    }

    return $next($payload);
});

What do you think?

@simonerd

simonerd commented Jul 2, 2025

Copy link
Copy Markdown
Contributor Author

I realised that I should be able to use the EntryBlueprintFound event to achieve the same without an additional hook. Yeah I know, it's almost like there's someone in the core team that constantly reminds us to read the flippin manual. Closing this for now.

@simonerd simonerd closed this Jul 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant